var app = getApp();

Page({
  data: {
    certification: '',
    realName: '',
    identity: '',
    mobile: '',
    real_name: '',
    id_card: '',
  },
  onLoad: function(options) {
    var that = this;
    that.setData({
      certification: wx.getStorageSync("certification"),
      realName: wx.getStorageSync("realName"),
      identity: wx.getStorageSync("identity")
    });
  },
  mobileTap: function(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  realNameTap: function(e) {
    this.setData({
      real_name: e.detail.value
    })
  },
  idCardTap: function(e) {
    this.setData({
      id_card: e.detail.value
    })
  },
  certificationTap: function(e) {
    var that = this;

    //判断是否输入真实姓名
    if (that.data.real_name == '') {
      wx.showModal({
        title: '提示',
        content: '请输入最低赏金!',
        showCancel: false,
        success: function(res) {}
      });
      return false;
    }

    //判断是否输入实名认证手机号
    if (that.data.mobile == '') {
      wx.showModal({
        title: '提示',
        content: '请输入实名认证手机号!',
        showCancel: false,
        success: function(res) {}
      });
      return false;
    }

    //判断是否输入身份证号
    if (that.data.id_card == '') {
      wx.showModal({
        title: '提示',
        content: '请输入预身份证号!',
        showCancel: false,
        success: function(res) {}
      });
      return false;
    }

    //实名认证提交
    var jsonData = {
      mobile: that.data.mobile,
      real_name: that.data.real_name,
      id_card: that.data.id_card,
    };
    app.showLoading("正在提交...请稍后...");
    app.JsonPost("Api/Auth/identification", jsonData, function (data) {
      console.log(data);
      app.closeLoading();
      if (data !== false) {
        wx.showModal({
          title: '提示',
          content: '提交成功!',
          showCancel: false,
          success: function (res) {
            wx.setStorageSync("certification", "true");
            wx.setStorageSync("mobile", that.data.mobile);
            wx.setStorageSync("realName", that.data.real_name);
            wx.setStorageSync("identity", that.data.id_card);
            that.setData({
              certification: "true",
              mobile: '',
              real_name: '',
              id_card: ''
            });
            that.onLoad();
          }
        });
      }

    })
  }
})